﻿namespace IBTrader.Indicator.Average
{
    using IBTrader.Modules.Read;
    using IBTrader.Charts;
    using System.Linq;

    class WMA : SMA
    {
        private readonly double k;
        private readonly bool reverse;
        public WMA(Worker worker, double interval = 60, bool reverse = false) : base(worker, interval) { k = interval * (interval + 1); this.reverse = reverse; }
        protected override double CalcPrice()
        {
            return Enumerable.Range(0, Prices.Length).Sum(i => Prices[reverse ? Prices.Length - 1 - i : i] * ((i + 1) / k) * 2);
        }
    }
}